Quaqua 3.9.5 2007-10-21

ch.randelshofer.quaqua.filechooser
Class AliasFileSystemTreeModel

java.lang.Object
  extended by ch.randelshofer.quaqua.filechooser.AliasFileSystemTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

public class AliasFileSystemTreeModel
extends java.lang.Object
implements javax.swing.tree.TreeModel

The AliasFileSystemTreeModel provides the data model for the JBrowser in a QuaquaFileChooserUI. It is capable of resolving aliases to files, and it updates its content asynchronously to the AWT Event Dispatcher thread.

Version:
1.20 2007-04-29 Resolve file aliases without user interaction when they are displayed in the chooser. Resolve file aliases with user interaction, when the user clicks on an alias.
1.19.1 2007-02-10 Use a static instance for OSXCollator, because creating a OSXCollator is very expensive.
1.19 2007-01-29 Only fire tree node changed, when something changed.
1.18 2006-09-23 Invalidate the user name of a file when invalidateInfo is called.
1.17.2 2006-06-13 Really be less lazy.
1.17.1 2006-06-07 Be less lazy in method lazyInvalidatePath.
1.17 2006-05-17 Removed short-circuit. We must explicitly check whether a file is a directory.
1.16 2006-04-07 Use a thread pool for reading directory listings. New directories listings are validated in LIFO order, old directory listings are validated in FIFO order. Reduced number of IO operations in DirectoryValidator.
1.15 2006-02-06 Moved COMPUTER constant from QuaquaPantherFileChooserUI to here.
1.14 2005-11-26 Lazily validate file infos in worker thread. Renamed validation code for children to validateChildren to make the difference between info validation and child validation clear. Implemented FileInfo interface.
1.13 2005-09-24 Support ordering by type.
1.12 2005-09-06 Node.toString returns user name of file object. This is needed to make cell tips on the JBrowser work properly.
1.11 2005-08-26 Replaced aFile.getParentFile() invocations with aFileSystemView.getParentDirectory() invocations where applicable.
1.10 2005-07-28 Reduced the number of File.exists() and FileChooser.isTraversable() method invocations to improve performance.
1.9 2005-06-18 Added file kind "widget" for directories with a ".wdgt" suffix in their name.
1.8.3 2005-06-07 Renamed "enum" variables, because "enum" is a reserved word in Java 1.5.
1.8.2 2005-03-23 Normalize a file object before attempting to create a path in method toPath().
1.8.1 2005-03-14 Fixed an IllegalStateException which occured in method toPath(), when attempting to create a path using an invalid File object.
1.8 2005.01-23 Support for file labels added. CollationKey's are now used to improve the performance of file sorting and merging.
1.7.1 2004-12-28 Renamed class QuaquaFileSystemView to QuaquaFileSystemView.
1.7 2004-11-28 Fixed class cast exception which occured, when a JFileChooser did not use an instance of QuaquaFileSystemView.
1.6 2004-11-21 Check the modification time of a directory to decide whether we need to validateChildren its contents.
1.5 2004-10-31 Require a QuaquaFileSystemView. Treat the computer folder system differently than other folders.
1.4.1 2004-09-11 Replaced all method invocations to method QuaquaManager.getProperty to QuaquaManager.getProperty.
1.4 2004-04-23 Method stopValidation() added. Fixed a bug in method Node.run(), which caused application bundles being constantly added and removed from the tree.
1.3 2004-03-13 Up to now, retrieving a directory from a remote computer took way too long. This version contains an all new update strategy for the tree nodes, and a new two step merging algorithm. There are now two different strategies to invalidateChildren the tree model: lazyInvalidateChildren and invalidateChildren. Lazy Invalidation should be used to refresh the tree model when the user selects a path in the JFileChooser. (Non-Lazy)-Invalidation should be used to refresh the tree model when the JFileChooser changes its visible state and when the FileFilter's used by the JFileChooser change. Method setAutoValidate can be used to turn Lazy Invalidation off.
1.2 2004-02-14 Don't read hidden files if file hiding is switched on in the JFileChooser. Reduced the number of method calls to JFileChooser.getName(). This greatly improves the performance of file choosers.
1.0.1 2004-02-06 Fixed some Javadoc warnings.
1.0 September 5, 2003 Created.
Author:
Werner Randelshofer

Nested Class Summary
 class AliasFileSystemTreeModel.AliasDirectoryNode
           
 class AliasFileSystemTreeModel.AliasNode
           
 class AliasFileSystemTreeModel.DirectoryNode
          This is the implementation for a directory node (a composite node).
 class AliasFileSystemTreeModel.Node
          This is the implementation for a file node (a leaf node).
 
Field Summary
static java.io.File COMPUTER
           
static int INVALID
          This is used for keeping track of the validation state of a node.
protected  javax.swing.event.EventListenerList listenerList
          We store all our listeners here.
static int VALID
          This is used for keeping track of the validation state of a node.
static int VALIDATING
          This is used for keeping track of the validation state of a node.
 
Constructor Summary
AliasFileSystemTreeModel(javax.swing.JFileChooser fileChooser)
          Creates a new instance.
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
          Adds a listener for the TreeModelEvent posted after the tree changes.
 void clear()
          Removes all children from the root node.
protected  AliasFileSystemTreeModel.Node createNode(java.io.File f)
          Creates a node for the specified file.
 void dispatchAliasResolution(java.lang.Runnable r)
           
 void dispatchDirectoryUpdater(java.lang.Runnable r)
           
 void dispatchFileUpdater(java.lang.Runnable r)
           
protected  void fireTreeNodeChanged(AliasFileSystemTreeModel.Node node)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesInserted(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesRemoved(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeStructureChanged(java.lang.Object source, java.lang.Object[] path)
          Notifies all listeners that have registered interest for notification on this event type.
 java.lang.Object getChild(java.lang.Object parent, int index)
           
 int getChildCount(java.lang.Object parent)
           
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
           
 AliasFileSystemTreeModel.Node getPrototypeValue()
           
 java.lang.Object getRoot()
           
 void invalidateAll()
          Invalidates all nodes in the tree.
 void invalidateCache()
           
 void invalidatePath(javax.swing.tree.TreePath path)
          Invalidates the provided path.
 boolean isAutoValidate()
           
 boolean isLeaf(java.lang.Object node)
           
 boolean isResolveAliasesToFiles()
           
 boolean isResolveFileLabels()
           
 void lazyInvalidatePath(javax.swing.tree.TreePath path)
          Lazily invalidates the provided path.
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
          Removes a listener previously added with addTreeModelListener().
 void setAutoValidate(boolean b)
          Sets auto validation of the tree.
 void setResolveAliasesToFiles(boolean newValue)
           
 void setResolveFileLabels(boolean newValue)
           
 void stopValidation()
          Stalls validation of the the provided path.
 javax.swing.tree.TreePath toPath(java.io.File file, javax.swing.tree.TreePath templatePath)
           
 javax.swing.tree.TreePath toPath0(java.io.File file)
           
 void validatePath(javax.swing.tree.TreePath path)
          Validates (refreshes) the nodes specified by the provided path.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
          Messaged when the user has altered the value for the item identified by path to newValue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPUTER

public static final java.io.File COMPUTER

INVALID

public static final int INVALID
This is used for keeping track of the validation state of a node.

See Also:
Constant Field Values

VALIDATING

public static final int VALIDATING
This is used for keeping track of the validation state of a node.

See Also:
Constant Field Values

VALID

public static final int VALID
This is used for keeping track of the validation state of a node.

See Also:
Constant Field Values

listenerList

protected javax.swing.event.EventListenerList listenerList
We store all our listeners here.

Constructor Detail

AliasFileSystemTreeModel

public AliasFileSystemTreeModel(javax.swing.JFileChooser fileChooser)
Creates a new instance.

Parameters:
fileChooser - The JFileChooser is used to determine the user presentable (localized) names of the files.
Method Detail

dispatchDirectoryUpdater

public void dispatchDirectoryUpdater(java.lang.Runnable r)

dispatchFileUpdater

public void dispatchFileUpdater(java.lang.Runnable r)

dispatchAliasResolution

public void dispatchAliasResolution(java.lang.Runnable r)

clear

public void clear()
Removes all children from the root node.


getPrototypeValue

public AliasFileSystemTreeModel.Node getPrototypeValue()

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Specified by:
getChild in interface javax.swing.tree.TreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
Specified by:
getChildCount in interface javax.swing.tree.TreeModel

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel

getRoot

public java.lang.Object getRoot()
Specified by:
getRoot in interface javax.swing.tree.TreeModel

createNode

protected AliasFileSystemTreeModel.Node createNode(java.io.File f)
Creates a node for the specified file. This is used to create nodes depending on their type (file, directory, alias to file, or alias to directory) and depending on the "resolveAliases" property.


toPath

public javax.swing.tree.TreePath toPath(java.io.File file,
                                        javax.swing.tree.TreePath templatePath)

toPath0

public javax.swing.tree.TreePath toPath0(java.io.File file)

isLeaf

public boolean isLeaf(java.lang.Object node)
Specified by:
isLeaf in interface javax.swing.tree.TreeModel

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Messaged when the user has altered the value for the item identified by path to newValue. If newValue signifies a truly new value the model should post a treeNodesChanged event.

Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel
Parameters:
path - path to the node that the user has altered
newValue - the new value from the TreeCellEditor

setAutoValidate

public void setAutoValidate(boolean b)
Sets auto validation of the tree. If the tree is autovalidating, it synchronizes its content with the file system.


isAutoValidate

public boolean isAutoValidate()

setResolveAliasesToFiles

public void setResolveAliasesToFiles(boolean newValue)

isResolveAliasesToFiles

public boolean isResolveAliasesToFiles()

setResolveFileLabels

public void setResolveFileLabels(boolean newValue)

isResolveFileLabels

public boolean isResolveFileLabels()

invalidateCache

public void invalidateCache()

invalidatePath

public void invalidatePath(javax.swing.tree.TreePath path)
Invalidates the provided path. This should be used to invalidateChildren the tree model when there are significant changes in the JFileChooser. Such as showing the JFileChooser and changing the FileFilters of the JFileChooser. To actually get a refresh of the tree, validatePath must be called.


invalidateAll

public void invalidateAll()
Invalidates all nodes in the tree. This should be used to invalidate the tree model when there are significant changes in the JFileChooser. To actually get a refresh of the tree, validatePath must be called.


stopValidation

public void stopValidation()
Stalls validation of the the provided path. This should be used to stop validation of the tree model when it is no longer needed.


lazyInvalidatePath

public void lazyInvalidatePath(javax.swing.tree.TreePath path)
Lazily invalidates the provided path. This should be used to trigger lazy refreshes of the tree model when the user navigates through the tree.


validatePath

public void validatePath(javax.swing.tree.TreePath path)
Validates (refreshes) the nodes specified by the provided path. Validation is done for nodes only, which have been marked as invalid. The validation is done asynchronously in worker threads.


addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener l)
Adds a listener for the TreeModelEvent posted after the tree changes.

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
l - the listener to add
See Also:
removeTreeModelListener(javax.swing.event.TreeModelListener)

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
Removes a listener previously added with addTreeModelListener().

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
l - the listener to remove
See Also:
addTreeModelListener(javax.swing.event.TreeModelListener)

fireTreeNodeChanged

protected void fireTreeNodeChanged(AliasFileSystemTreeModel.Node node)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
node - the node being changed
See Also:
EventListenerList

fireTreeNodesChanged

protected void fireTreeNodesChanged(java.lang.Object source,
                                    java.lang.Object[] path,
                                    int[] childIndices,
                                    java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node being changed
path - the path to the root node
childIndices - the indices of the changed elements
children - the changed elements
See Also:
EventListenerList

fireTreeNodesInserted

protected void fireTreeNodesInserted(java.lang.Object source,
                                     java.lang.Object[] path,
                                     int[] childIndices,
                                     java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where new elements are being inserted
path - the path to the root node
childIndices - the indices of the new elements
children - the new elements
See Also:
EventListenerList

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(java.lang.Object source,
                                    java.lang.Object[] path,
                                    int[] childIndices,
                                    java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where elements are being removed
path - the path to the root node
childIndices - the indices of the removed elements
children - the removed elements
See Also:
EventListenerList

fireTreeStructureChanged

protected void fireTreeStructureChanged(java.lang.Object source,
                                        java.lang.Object[] path)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where the tree model has changed
path - the path to the root node
See Also:
EventListenerList

Copyright 2003-2007 (c) Werner Randelshofer.
All rights reserved.